<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>table拖拽</title>
  <style>
    .box {
      display: table;
      width: 500px;
      height: 500px;
      background-color: skyblue;
      margin: 0 auto;
      border-collapse: collapse;
    }

    .row {
      display: table-row;
      background-color: red;
      pointer-events: auto;
    }

    .col {
      display: table-cell;
      border: 1px solid #000;
      text-align: center;
      line-height: 500px;
    }

    #cell {
      width: 50px;
      height: 50px;
      background-color: aqua;
      line-height: 50px;
    }
  </style>
</head>

<body>
  <div class="col" id="cell" draggable="true">123</div>
  <div class="box">
    <div class="row">
      <!-- <div class="col">123</div>
      <div class="col">123</div>
      <div class="col">123</div>
      <div class="col">123</div> -->
    </div>
  </div>
</body>

</html>
<script>
  let cell = document.querySelector("#cell");

  


  let box = document.querySelector(".box");

  box.ondragover = function (ev) {
    ev.preventDefault();
  }

  let counter = 0;

  box.ondrop = function () {
    counter++;
    let col = document.createElement('div');
    col.className = 'col';
    col.innerText = counter;
    this.appendChild(col);
  }

  let row = document.querySelector(".row");

  row.ondragover = function (ev) {
    ev.preventDefault();
  }

  box.onclick = function(){
    console.log('box');
  }

  row.onclick = function(){
    console.log('row');
  }

  row.ondrop = function () {
    counter++;
    let col = document.createElement('div');
    col.className = 'col';
    col.innerText = counter;
    this.appendChild(col);
  }












</script>